
#include <stdlib.h>
#include <assert.h>
#include <SDL/SDL.h>


/*
 * Return the pixel value at (x, y)
 * NOTE: The surface must be locked before calling this!
 */

Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
    int bpp = surface->format->BytesPerPixel;

    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

    switch(bpp)
    {
    case 1:
        return *p;

    case 2:
        return *(Uint16 *)p;

    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
            return p[0] << 16 | p[1] << 8 | p[2];
        else
            return p[0] | p[1] << 8 | p[2] << 16;

    case 4:
        return *(Uint32 *)p;

    default:
        return 0;
    }

}




int collision(SDL_Surface *font,int x, int y)
{
    Uint8 *colors;
    Uint32 pixel;
    int R,G,B,alpha;

    pixel=getpixel(font,x,y);
    colors = (Uint8*)&pixel;

    B=colors[0];
    G=colors[1];
    R=colors[2];
    alpha=colors[3];

    //fprintf(stdout,"\nR=%d G=%d B=%d alpha=%d",R,G,B,alpha);
    if(R == 255 && G == 255 && B == 255)
        return(1);
    if (R==255 && G==0 && B==0)
        return(2);

    else
        return(0);

}

